package com.yunao.commons.metasearch.cookie;


import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class TencentCookie {
    public static void main(String[] args) throws IOException {
        System.out.println(new TencentCookie().load("", ""));
    }

    public TencentCookie() {

    }

    public TencentCookie(String proxyHost, int proxyPort, String proxyUsername,
                         String proxyPassword) {

    }

    public Map<String, String> load(String username, String password)
            throws IOException {
        File file;
        try {
            URL url = TencentCookie.class.getClassLoader().getResource("client/tencent.dat");
            file = new File(url.getFile());
        } catch (Exception e) {
            return null;
        }

        String text = FileUtils.readFileToString(file);

        Map<String, String> result = new HashMap<String, String>();
        String[] cookies = StringUtils.split(text, ",");
        for (String cookie : cookies) {
            result.put(StringUtils.substringBefore(cookie, "="),
                    StringUtils.substringAfter(text, "="));
        }
        return result;
    }

}
